<?php
class omeauto_auto{
    private $_view;
    
    function __construct($app){
        $this->app = $app;
        $this->condition = get_class($this);
    }
    
    function set_view($view){
        $this->_view = $view;
    }
    
    function get_render(){
        $render = $this->app->render();
        
        $render->pagedata['PREFIX'] = $this->condition;
        $render->pagedata['KEY'] = uniqid();
        $render->pagedata['CONDITION'] = $this->condition;
        
        return $render;
    }
    
    function get_conditions($type){
        $conditions = array();
        foreach(kernel::servicelist($type) as $object){
            $condition = get_class($object);
            $conditions[$condition] = array(
                'name' => $object->name,
                'condition' => $condition,
            );
        }
        return $conditions;
    }
    
    function get_condition_detail($condition,$data=array()){
        return kernel::single($condition)->condition_detail($data);
    }
    
    /*
     * 可重载自定义
     * 
     * 显示条件的详细html信息
     * 
     * @param string $condition 条件名（类名）
     * @param array $data 存的是多个相同条件的参数 array(
     *                                              array(
     *                                                  'xxx' => 'xxx',
     *                                                  'xxx' => 'xxx',
     *                                              ),
     *                                              array(
     *                                                  'xxx' => 'xxx',
     *                                                  'xxx' => 'xxx',
     *                                              ),
     *                                              ......
     *                                           )
     * 
     */
    function condition_detail($data){
        $render = $this->get_render();
        
        //各自定义pagedata方法，目的是在产生各自条件的页面时产生各自的smarty变量
        if(method_exists($this,'pagedata')){
            $pagedata = $this->pagedata($data);
            if($pagedata){
                foreach($pagedata as $k=>$v){
                    $render->pagedata[$k] = $v;
                }
            }
        }
        
        if($this->_view){
            $view = $this->_view;
        }else{
            $view = "condition/".$this->condition.".html";
        }
        
        return $render->fetch($view);
    }
    
    function get_detail_basic($data){
        $detail = array();
        if($data){
            foreach($data as $condition=>$value){
                foreach($value as $v){
                    $detail[] = kernel::single($condition)->detail_basic($v);
                }
            }
        }
        
        return $detail;
    }
    
    /*
     * 可自定义重载
     * 
     * 用于显示下拉详情
     * @params array $data 每个条件的数据
     */
    function detail_basic($data){
        
    }
    
    /*
     * 验证订单的sdf数据条件是否通过
     * 
     * @params array $order_sdf 订单sdf结构
     * @params array $condition_data 条件的数据
     */
    function validate($order_sdf,$condition_data){
        
    }
}